package com.d3works.apps.businessproject.web;

import com.d3works.apps.businessproject.service.ProjectAnalyticMoveLineService;
import com.d3works.apps.purchase.db.PurchaseOrder;
import com.d3works.apps.purchase.db.repo.PurchaseOrderRepository;
import com.d3works.exception.service.TraceBackService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;

@Singleton
public class PurchaseOrderProjectController {

  public void updateLines(ActionRequest request, ActionResponse response) {
    try {
      PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
      purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
      purchaseOrder = Beans.get(ProjectAnalyticMoveLineService.class).updateLines(purchaseOrder);
      response.setValue("purchaseOrderLineList", purchaseOrder.getPurchaseOrderLineList());
    } catch (Exception e) {
      TraceBackService.trace(response, e);
    }
  }
}
